import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wallpaper/components/images/image_load.dart';
import 'package:wallpaper/components/images/image_view.dart';
import 'package:wallpaper/providers/setting_provider.dart';
import 'package:wallpaper/tools/route_animation.dart';

class BuildItem extends StatelessWidget {
  final List imgs;
  final int index;
  final bool isZip;
  final bool isMobile;
  const BuildItem({
    super.key,
    required this.imgs,
    required this.index,
    this.isZip = false,
    this.isMobile = false,
  });

  @override
  Widget build(BuildContext context) {
    final SettingProvider setting = Provider.of<SettingProvider>(context);
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(setting.radius),
      ),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(setting.radius),
        child: Stack(alignment: Alignment.bottomLeft, children: [
          SizedBox(
            width: double.infinity,
            height: double.infinity,
            child: ImageLoad(
              imageUrl: imgs[index].smallPath,
            ),
          ),
          if (imgs[index].tags != "")
            SizedBox(
                width: double.infinity,
                child: Container(
                  padding: const EdgeInsets.all(3),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      colors: [
                        Colors.black.withOpacity(0),
                        Colors.black.withOpacity(1),
                      ],
                    ),
                  ),
                  child: Text(
                    imgs[index].tags,
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                    style: TextStyle(color: Colors.white, fontSize: 13),
                  ),
                )),
          Positioned.fill(
            child: Material(
              color: Colors.transparent,
              child: InkWell(
                borderRadius: BorderRadius.circular(setting.radius),
                onTap: () {
                  FocusScope.of(context).requestFocus(FocusNode());
                  RouteAnimation().animateRoute(
                      context,
                      ImageView(
                        images: imgs,
                        selectedIndex: index,
                        isMobile: isMobile,
                        resetGetdata: () {},
                      ));
                },
              ),
            ),
          )
        ]),
      ),
    );
  }
}
